﻿$(function () {
    $('.form-datetime-lang').datetimepicker({
        language: 'zh-CN',
        format: 'yyyy-mm-dd hh:ii:ss'
    });

    $("#btnSearch").click(function () {
        var  startTime = $("#txtStartTime").val();
        var endTime = $("#txtEndTime").val();
        Index_load_page(startTime, endTime, page_index);
    });


    $('#Qrcode').qrcode({
        text: $("#Promoter").prev().text(),//要生产二维码的文字
        render: "canvas",
        width: 150,  
        height: 150,
        correctLevel: 3, // 纠错级别，可取 0、1、2、3，数字越大说明所需纠错级别越大
        background: "#ffffff", // 背景色
        foreground: "#000000" // 前景色
    });

    $("#btnRegister").click(function () {
        window.location.href = "/VipRegister.aspx?accountid="+ account;
    });


    var clipboard = new Clipboard('.btn', {
        text: function () {
            return $("#Promoter").prev().text();
        }
    });
    clipboard.on('success',
    function (e) {
        alert("复制成功");
    });
    clipboard.on('error',
    function (e) {
        console.log(e);
    });


    //$("img").click(function () {
    //    var width = $(this).width();
    //    if (width == 150) {
    //        $(this).width(100);
    //        $(this).height(120);
    //    }
    //    else {
    //        $(this).width(150);
    //        $(this).height(180);
    //    }
    //});

    $("#ltIsRead").change(function () {
        var url = location.href;
        var reg = /read=.+\&?/;
        if (reg.test(url)) {
            location.href = url.replace(reg, "read=" + $(this).val());
        }
        else {
            location.href = "?read=" + $(this).val();
        }
    });

    $("#selectMonth").change(function (e) {
        var url = location.href;
        var reg = /currentMonth=.+\&?/;
        if (reg.test(url)) {
            location.href = url.replace(reg, "currentMonth=" + $(this).val());
        }
        else {
            location.href = "?currentMonth=" + $(this).val();
        }
    });

    $("#selectYear").change(function (e) {
        var url = location.href;
        var reg = /currentYear=.+\&?/;
        if (reg.test(url)) {
            location.href = url.replace(reg, "currentYear=" + $(this).val());
        }
        else {
            location.href = "?currentYear=" + $(this).val();
        }
    });
});



var keys = $("#txtkey").val();
var lot = parseInt($("#ltLotteryCode").val());
var recordcount = parseInt($("#RecordCount").text());
var page_index = parseInt($("#PageIndex").text());
var page_size = parseInt($("#PageSize").text());
var tPage = parseInt((recordcount % page_size) > 0 ? (recordcount / page_size) + 1 : (recordcount / page_size));

function pages(cPage) {

    var startTime = $("#txtStartTime").val();
    var endTime = $("#txtEndTime").val();
    //业务代码块  
    //分页按钮组控制块  
    var param = {
        "cPage": cPage,
        "tPage": tPage,
        "clickFun": "pages",
        "showLast": false,
        "div": { "float": "right" }
    };
    $("#ul_pages").simplePaging(param);

    var currentUrl = location.href;
    if (-1 < currentUrl.indexOf("Index.aspx"))
        Index_load_page(startTime, endTime, cPage);
    else if (-1 < currentUrl.indexOf("MyNotice.aspx"))
        Notice_load_page(cPage);
    else if (-1 < currentUrl.indexOf("Extensionecord.aspx"))
        Notice_load_page(cPage);
}


function load() {
    var param = {
        "cPage": page_index,
        "tPage": tPage,
        "clickFun": "pages",  //该函数接受一个cPage参数  
        "showLast": false,
        "div": { "float": "right" }
    };
    if (recordcount > 0)
        $("#ul_pages").simplePaging(param);
}

function Index_load_page(startTime,endTime,cPage) {
    var url = "Index.aspx?startTime=" + startTime + "&endTime=" + endTime + "&PageIndex=" + cPage;
    window.location.href = url;
}

function MyBrokerage_Load_page(startTime, endTime, cPage) {
    var url = "MyBrokerage.aspx?startTime=" + startTime + "&endTime=" + endTime + "&PageIndex=" + cPage;
    window.location.href = url;
}

function Brokerage_Load_page(startTime, endTime, cPage) {
    var url = "Brokerage.aspx?startTime=" + startTime + "&endTime=" + endTime + "&PageIndex=" + cPage;
    window.location.href = url;
}

function Users_Load_page(cPage) {
    var url = "MyUsers.aspx?keys=" + escape(keys) + "&page=" + cPage;
    window.location.href = url;
}

function BrokerageDetail_Load_page(cPage, clot) {
    var url = "BrokerageDetail.aspx?keys=" + escape(keys) + "&lot=" + clot + "&page=" + cPage;
    window.location.href = url;
}

$("#btnDetailSearch").click(function () {
    keys = $("#txtkey").val();
    lot = parseInt($("#ltLotteryCode").val());
    BrokerageDetail_Load_page(1, lot);
});

$("#btnUsersSearch").click(function () {
    keys = $("#txtkey").val();
    Users_Load_page(1);
});

///////////////////////////////////MyNotice//////////////////////////////

function Notice_load_page( page) {
    var url = location.href;
    var reg = /page=.+\&?/;
    if (reg.test(url)) {
        location.href = url.replace(reg, "page=" + page);
    }
    else {
        if (-1 < location.href.indexOf("?"))
            location.href += "&page=" + page;
        else
            location.href = "?page=" + page;
    }
}

$("#btnSearchNotice").click(function () {
    var keys = $("#txtkey").val();
    var ltIsRead = $("#ltIsRead").val();
    var reg;
    var url = location.href;

    if (keys) {
        reg = /Keys=.+\&?/;
        if (reg.test(url)) {
            url = url.replace(reg, "Keys=" + keys);
        }
        else {
            if (-1 < url.indexOf("?"))
                url += "&Keys=" + keys;
            else
                url = "?Keys=" + keys;
        }
    }

    if (ltIsRead) {
        reg = /read=.+\&?/;
        if (reg.test(url)) {
            url = url.replace(reg, "read=" + ltIsRead);
        }
        else {
            if (-1 < url.indexOf("?"))
                url += "&read=" + ltIsRead;
            else
                url = "?read=" + ltIsRead;
        }
    }
    location.href = url;
});

$("#btnSearchExtenSion").click(function (e) {
    var url = location.href;
    var search = $("#txtkey").val();
    var reg = /search=.+\&?/;
    if (reg.test(url)) {
        location.href = url.replace(reg, "search=" + search);
    }
    else {
        location.href = "?search=" + search;
    }
});


function onReadSuccessed(result) {
    Notice_load_page(1, ltIsRead, '');
}

function OnClickDeleteNotice(noticeID) {
    var bCom = confirm("确定删除?");
    if (bCom) {
        $.post("/PostMsg.aspx", "posttype=delete_notice&noticeID=" + noticeID, function (e) {
            if ("ok" == e) {
                location.reload();
            }
            else{
                alert("删除失败, 请稍后重试!");
            }
        });
    }
}


///////////////////////////////////**MyNotice**//////////////////////////////

///////////////////////////////////MyBrokerage//////////////////////////////

function MyBrokerage_load_page(startTime, endTime, cPage) {
    var url = "MyBrokerage.aspx?startTime=" + startTime + "&endTime=" + endTime + "&PageIndex=" + cPage;
    window.location.href = url;
}


///////////////////////////////////**MyBrokerage**//////////////////////////////

function verifypwd() {
    var UnionPassword = $("#txtUnionPassword").val(); //旧密码
    var NewUnionPassword = $("#txtNewUnionPassword").val(); //新密码
    var AffirmUnionPassword = $("#txtAffirmUnionPassword").val(); //确认新密码
    if (UnionPassword == '') {
        $("#lbMsg").text("请输入您的登录密码");
        return false;
    }
    if (NewUnionPassword == '') {
        $("#lbMsg").text("请输入您的新登录密码");
        return false;
    }
    if (AffirmUnionPassword == '') {
        $("#lbMsg").text("请确认新登录密码");
        return false;
    }
    if (NewUnionPassword != AffirmUnionPassword) {
        $("#lbMsg").text("确认密码与新密码不一致");
        return false;
    }
    return true;
}

